package edu.uw.tcss360.group6.model;//need to discuss the "editEntry()" method to find out what functionality to include.

//Make others aware of getCategory vs getCategories

//HashTable vs array

import java.util.HashSet;

/**
 * Author: David Sharer
 */
@SuppressWarnings("serial")
public class Contestant extends User implements java.io.Serializable {

	private Entry[] my_entries; //we had a hash table here in the UML, but only 3 elements max...
	
	private int my_num_entries;
	
	public Contestant(User info) {
        super(info);
		my_entries = new Entry[3];
		my_num_entries = 0;
	}
	
	public Entry[] getEntries() {
        HashSet<Entry> entries= new HashSet<Entry>();
        for(int i = 0; i < 3; i++) {
            if( my_entries[i] != null)
                entries.add(my_entries[i]);
        }
        return entries.toArray(new Entry[entries.size()]);
	}
	//added Mais
	public void setEntry(Entry the_entry, int index)
	{
		if(my_num_entries >= 3)
            throw new IllegalStateException("edu.uw.tcss360.group6.model.Contestant can only have 3 entries.");
		my_entries[index] = the_entry;
	}
	//public Entry[] set
	
	public Category[] getCategories() {
        HashSet<Category> categories = new HashSet<Category>();
		for(int i = 0; i < 3; i++) {
			if( my_entries[i] != null)
                categories.add(my_entries[i].getCategory());
		}
		return categories.toArray(new Category[categories.size()]);
	}

    public int getNumberOfEntries() {
        return my_num_entries;
    }

    /**
     * For internal use only. DO NOT USE. Use {@Contest.addEntry}
     * @param weave_entry
     */
	protected void associateEntry(Entry weave_entry) {
        if(my_num_entries >= 3)
            throw new IllegalStateException("edu.uw.tcss360.group6.model.Contestant can only have 3 entries.");
        my_entries[my_num_entries] = weave_entry;
        my_num_entries++;
//		if(my_num_entries < 3) { //make sure that contestant only enters a max of 3 entries.
//			my_entries[my_num_entries] = weave_entry;
//			my_num_entries++;
//		} //logic moved to edu.uw.tcss360.group6.model.Contest
	}
	
	
	
}
